package GoogleSearch.test;

import java.rmi.RemoteException;

import javax.xml.rpc.ServiceException;

import GoogleSearch.GoogleSearchPort;
import GoogleSearch.GoogleSearchResult;
import GoogleSearch.GoogleSearchServiceLocator;
import GoogleSearch.ResultElement;

public class ClientGoogle {

  public static void main(String[] args) throws ServiceException,
    RemoteException {
    String clientKey = "122121231";
    GoogleSearchServiceLocator service = new GoogleSearchServiceLocator();
    GoogleSearchPort gsp = service.getGoogleSearchPort();

    //Google Search API
    GoogleSearchResult searchResult = gsp.doGoogleSearch(clientKey,
        "www.williamlong.info", 0, 10, false, "", false, "", "latin1",
        "latin1");
    System.out.println("Google Search Results:");
    System.out.println("======================");
    ResultElement results[] = searchResult.getResultElements();
    for (int counter = 0; counter < results.length; ++counter) {
      ResultElement result = results[counter];
      String returnResult = "('" + result.getTitle() + "','"
          + result.getURL() + "','" + result.getSnippet() + "')";
      System.out.println("Return Result");
      System.out.println(returnResult);
    }

    //Google CachedPage
    byte[] cachedBytes = gsp.doGetCachedPage(clientKey,
        "http://www.williamlong.info/");
    System.out.println("Cached page:");
    System.out.println("============");
    String cachedString = new String(cachedBytes);
    System.out.println(cachedString);

    //Google SpellingSuggestion
    String suggestion = (String) gsp.doSpellingSuggestion(clientKey,
        "williamlong");
    System.out.println(suggestion);

  }

}
